<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS元素选择器</title>
</head>
<body>
    <div class="box">
        <ul>
            <li>1</li>
            <li id="li2">2</li>
            <li>3</li>
            <li>4</li>
        </ul>
    </div>

    <script>
        // 根据类名获取元素
        const box = document.querySelector('.box')
        console.dir(box)

        // 根据ID名获取元素
        const li2 = document.querySelector('#li2')
        console.dir(li2)

        // 技巧CSS选择器怎么选择就怎么写
        const li3 = document.querySelector('ul li:nth-child(3)')
        console.dir(li3)

        // 选择多个标签
        const lis = document.querySelectorAll('li')
        console.dir(lis)
    </script>
</body>
</html>